//
//  SearchData.m
//  classmate2.0
//
//  Created by 90 on 15/5/25.
//  Copyright (c) 2015年 李昂Leon. All rights reserved.
//

#import "SearchData.h"


@implementation SearchData

@synthesize data;
@synthesize ary;

static SearchData * _instance;

+(id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t  onceToken;
    
    dispatch_once(&onceToken, ^{
        
        _instance = [super allocWithZone:zone];
        
    });
    return _instance;
}
+(instancetype)shareInstance
{
    if (!_instance) {
        _instance = [[SearchData alloc]init];
    }
    return _instance;
}


- (void)setData:(NSMutableArray *)tmpData
{
    data = tmpData;
    
    ary = [NSMutableArray arrayWithCapacity:10];
    
    for(NSArray *tmp in data)
    {
        for (NSString *str in tmp)
        {
            [ary addObject:str];
        }
    }
}

- (NSMutableArray *)searchStringForcharacter:(NSString*)searchStr
{
    NSMutableArray *tmp = [NSMutableArray arrayWithCapacity:10];
    for (NSString *str in ary)
    {
        if ([str hasPrefix:searchStr])
        {
            [tmp addObject:str];
        }
    }
    
    return [tmp count] > 0 ? tmp : nil;
}

- (NSArray *)getArrayForIndex:(NSUInteger)index
{
    return [data objectAtIndex:index];
}

- (NSInteger)getGroupingCount
{
    return [data count];
}
@end
















































